package com.kc.web.controller.business;

import com.kc.business.domain.BizBanner;
import com.kc.business.service.IBizBannerService;
import com.kc.common.annotation.Log;
import com.kc.common.annotation.RepeatSubmit;
import com.kc.common.core.controller.BaseController;
import com.kc.common.core.domain.AjaxResult;
import com.kc.common.core.page.TableDataInfo;
import com.kc.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO
 *
 * @author zhangshuo
 * @version 1.0
 * @date 2020/9/16
 */
@RestController
@RequestMapping("/business/banner")
public class BizBannerContorller extends BaseController {
    @Autowired
    private IBizBannerService bannerService;

    /**
     * 轮播图列表
     *
     * @param bizBanner
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizBanner bizBanner) {
        startPage();
        List<BizBanner> list = bannerService.getList(bizBanner);
        return getDataTable(list);
    }

    /**
     * 新增轮播图
     *
     * @param bizBanner
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:banner:add')")
    @Log(title = "轮播图管理", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@Validated @RequestBody BizBanner bizBanner) {
        return toAjax(bannerService.add(bizBanner));
    }

    /**
     * 修改轮播图
     *
     * @param bizBanner
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:banner:edit')")
    @Log(title = "轮播图管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(@Validated @RequestBody BizBanner bizBanner) {
        return toAjax(bannerService.edit(bizBanner));
    }

    /**
     * 删除轮播图
     *
     * @param bannerIds
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:banner:edit')")
    @Log(title = "轮播图管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{bannerIds}")
    @RepeatSubmit
    public AjaxResult delete(@PathVariable String bannerIds) {
        return toAjax(bannerService.delete(bannerIds));
    }

}
